import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class Libtxt {
    public static void create_txtx(String filename,String data,String encoding)
    {
        File file = new File(filename);
        try{
        file.createNewFile();
        FileWriter writer = new FileWriter(file);
        char[] head = new char[100];
        char[] encodeChars = encoding.toCharArray();
        for(int i=0;i<head.length;i++)
        {
            if(i<encodeChars.length)
            {
                head[i] = encodeChars[i];
            }
            else
            {
                head[i] = ' ';
            }
            
        }

        writer.write(head);
        writer.write(data);
        writer.close();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
    public static void main(String[] args)
    {
        create_txtx("test.txt","test","gbk");
    }
}